from django.shortcuts import render
from django.views import View
# Create your views here.
from apps.address.models import Area
from django import http


class AreasView(View):

    def get(self, request):

        try:
            # 获取区域数据
            zone_model_list = Area.objects.filter(name__isnull=False)

            zone_list = []
            for zone_model in zone_model_list:
                zone_list.append({'aid': zone_model.id,
                                  'aname': zone_model.name})

        except Exception as e:
            print(e)
            return http.JsonResponse({'errno': 4001, 'errmsg': '数据库查询错误'})

        return http.JsonResponse({'errno': 0, 'errmsg': 'ok', 'data': zone_list})
